<?php

namespace App\Controller\ShengJin;

use App\Base\BaseController4Api;
use App\Entity\ApiMoney;
use App\Entity\ApiUser;
use App\Model\ApiMoneyTypeModel;
use App\Model\ApiUserModel;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

use Symfony\Component\HttpFoundation\Request;


/**
 * @route("/api")
 */
class ApiUserController extends BaseController4Api
{

    /**
     * @route("/user_become_vip",name="ApiUserBecomeVip")
     */
    public function add()
    {
        $projectId = $this->getProjectId();
        if (!$uid = $this->getParamRequired("uid")) {return $this->json_out(0,"用户ID缺失");}
        $mo = new ApiUserModel($this->getDoctrine());
        $user = $mo->getUser($projectId,$uid);
        if ($user->getCat() == 1) {
            //升级到下一级别
            $user->setCat(2);
            $this->myEm()->persist($user);$this->myEm()->flush();
            return $this->json_out(1,"已升级为会员");
        }else{
            //啥也不干
            return $this->json_out(1,"已升级为会员");
        }
    }

}
